home *** CD-ROM | disk | FTP | other *** search
- #import "aGroup.h"
- #import "aGroup-inter.h"
- #import "TessSketch.h"
- #import "Underlay.h"
- #import "GeneratorOverlay.h"
- #import <math.h>
-
- @implementation aGroup
- +new
- {
- self = [super new];
- [self setAutosizing: NX_WIDTHSIZABLE | NX_HEIGHTSIZABLE];
- return self;
- }
-
- + setup
- {
- GroupSetup(); // call only once
- return self;
- }
-
- - setupControls
- {
- anglewin = [[superview superview] awin];
- [anglewin close];
- angle1slide = [[superview superview] a1slide] ;
- angle2slide = [[superview superview] a2slide] ;
- angle1box = [[superview superview] a1box] ;
- angle2box = [[superview superview] a2box] ;
- return self;
- }
-
- - drawSelf:(const NXRect *)rects :(int)rectCount
- {
- NXRect superframe;
- NXPoint offset;
- offset.x = offset.y = - GENOFFT;
- [genovly getFrame: &superframe];
- [self clip: 0 : 0 ];
- [[genovly getImage] composite: NX_COPY fromRect: &superframe toPoint: &offset];
- return self;
- }
-
- - setGenovly: sender
- {
- genovly = sender;
- return self;
- }
-
- - defaultConfig
- {
- return self;
- }
-
- - sizeTo: (float) x : (float) y
- {
- [super sizeTo: x : y];
- [self resizeGenerator];
- return self;
- }
-
- - resizeGenerator
- {
- return self;
- }
-
- - anglesDidChange
- {
- [self resizeGenerator];
- [superview erase];
- [superview display];
- return self;
- }
-
- - performTesselation: sender
- {
- id imgview,outview,outimg;
- NXPoint pt,genofft;
- NXSize lsize;
- NXRect outrect;
- float xstart;
-
- outview = [sender getOutputView];
- outimg = [outview getImage];
- [self getLatticeUnitSize: &lsize];
- [sender getImageView:&imgview withOffset: &genofft];
- if(![outimg lockFocus]) fprintf(stderr,"Couldn't lock outimg focus\n");
- PSgsave();
- [outview getFrame: &outrect];
- pt.x = pt.y = 0.0;
- while (pt.y < outrect.size.height + lsize.height){
- PSmoveto(0.0,0.0);
- while(pt.x > -lsize.width)
- [self leftTranslatePoint: &pt];
- xstart = pt.x;
- while (pt.x < outrect.size.width + 2*lsize.width) {
- PSgsave();
- PStranslate(pt.x,pt.y);
- [self makeLatticeUnitAt: &genofft fromImage: [imgview getImage]];
- PSgrestore();
- [self rightTranslatePoint: &pt];
- }
- pt.x = xstart;
- [self upTranslatePoint: &pt];
- }
- PSgrestore();
- [outimg unlockFocus];
- return self;
- }
-
- - generator: (NXCoord) x : (NXCoord) y
- {
- [self clip: x : y];
- PSstroke();
- return self;
- }
- - clip: (NXCoord) x: (NXCoord) y { return self; }
- - (BOOL) isRigidLattice { return YES; }
- - rightTranslatePoint: (NXPoint *) pt { return self; }
- - leftTranslatePoint: (NXPoint *) pt { return self; }
- - upTranslatePoint: (NXPoint *)pt { return self; }
- - (NXSize *)getLatticeUnitSize: (NXSize *) size
- {
- size->width = latticesize.width;
- size->height = latticesize.height;
- return &latticesize;
- }
- - drawImage
- {
- [self sketchTemplate];
- return self;
- }
- - sketchTemplate
- {
- return self;
- }
- - makeLatticeUnitAt: (NXPoint *) point fromImage: srcimg { return self; }
- - (NXPoint *)getGeneratorOffset: (NXPoint *) pt
- {
- pt->x = pt->y = 0.0;
- return pt;
- }
-
- - (NXSize *)getGeneratorSize: (NXSize *) size
- {
- return &frame.size;
- }
-
- - singleAngleSetup: (float) a
- {
- [anglewin makeKeyAndOrderFront: self];
- [angle1slide setEnabled: YES];
- [angle1slide setFloatValue: a];
- [angle2slide setEnabled: NO];
- [anglewin update];
- return self;
- }
-
- - twoAngleSetup: (float) a : (float) b
- {
- [anglewin makeKeyAndOrderFront: self];
- [angle1slide setEnabled: YES];
- [angle1slide setFloatValue: a];
- [angle2slide setEnabled: YES];
- [angle2slide setFloatValue: b];
- [anglewin update];
- return self;
- }
-
- - noAngleSetup
- {
- [anglewin close];
- return self;
- }
-
- - setAngle1: (float) a1
- {
- [angle1slide setFloatValue: a1];
- [self anglesDidChange];
- return self;
- }
- - setAngle2: (float) a2
- {
- [angle2slide setFloatValue: a2];
- [self anglesDidChange];
- return self;
- }
- - sizeKludge: (float *) x : (float *) y
- {
- *x = *y;
- return self;
- }
- @end
-
- int genfun () { return 1; }
- int clipper () { return 1; }
- int tesselate () { return 1;}
-
- defineps GroupSetup()
- /groupsdict 40 dict def
- groupsdict begin
- /equi { 3 sqrt mul 2 div } bind def
- /generatorcolor {0.655171 0.102771 0.629475 setrgbcolor } bind def
- /glidecolor {0.373226 0.462386 0.528733 setrgbcolor } bind def
- /reflectioncolor {0.333338 0.039216 0.237907 setrgbcolor } bind def
- /translationcolor {1 0.054903 0.101962 setrgbcolor } bind def
- /anglecolor { 0 0 1 setrgbcolor } bind def
- /latticeunitcolor { 0.5 setgray } bind def
- /scaling 1.0 def
-
- /arrow { % angle x y
- newpath moveto dup rotate
- -13 6 rlineto 4 -6 rlineto
- -4 -6 rlineto closepath gsave 0
- setlinejoin stroke grestore fill neg rotate
- } def
-
- /addpoints { % x y x y
- exch % x y y x
- 4 1 roll % y y x x
- add 3 1 roll % x y y
- add % x y
- } bind def
-
- /duptop2 { % x y -> x y x y
- dup % x y y
- 3 2 roll % y y x
- dup % y y x x
- 4 1 roll % x y y x
- exch % x y x y
- } bind def
-
- /even { % num
- cvi 1 and 1 eq not
- } bind def
-
- /setscaling { % scale - wrap with dictionary use !!!
- % groupsdict begin
- % /scaling exch def
- % [scaling 0 0 scaling 0 0] setmatrix
- % end
- pop
- } bind def
-
- /reflect { % angle
- dup rotate
- [1 0 0 -1 0 0] concat
- neg rotate
- } bind def
-
- /rhombus { % x y
- groupsdict begin
- moveto
- latticeunitcolor
- lattice:side 0 lineto
- lattice:w lattice:h rlineto
- lattice:side neg 0 rlineto
- closepath
- stroke
- end
- } bind def
-
- /transv0 { %x y len
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto dup 0 rlineto stroke
- 0 exch 0 arrow
- grestore
- end
- } bind def
-
- /transv90 { %x y len
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto dup 0 exch rlineto stroke
- 90 exch 0 exch arrow
- grestore
- } bind def
-
- /transv60 { %x y run rise
- groupsdict begin
- gsave
- 2 setlinewidth
- translationcolor
- moveto
- duptop2
- rlineto stroke
- 60 3 1 roll % angle of arrow
- arrow
- grestore
- end
- } bind def
-
- /reflectionaxis { % x1 y1 x2 y2
- groupsdict begin
- reflectioncolor
- moveto rlineto stroke
- end
- } bind def
-
- /rotation3 { % size x y
- groupsdict begin
- moveto
- /r3size exch def
- /r3ext r3size equi def
- anglecolor
- 0 r3ext 2 div rmoveto
- r3size 2 div r3ext neg rlineto
- r3size neg 0 rlineto
- closepath
- gsave fill grestore stroke
- end
- } bind def
- end
- endps
-
- defineps reflect(float angle)
- groupsdict begin
- angle reflect
- end
- endps
-